package com.qinghong.spring_trans2.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;

@Service
public class UserService2 {

    @Autowired
    JdbcTemplate jdbcTemplate;

//    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Transactional
    public void update(){
        jdbcTemplate.update("update user set money = ? where username = ?",1,"lisi");
//        int i = 1/0;

        // 隔离为REQUIRES_NEW时，把异常处理掉了可以让外面的不回滚
    }
}
